
import 'package:flutter/material.dart';
import 'package:flutter_fun_zjversion/config/resource_manager.dart';
import 'package:flutter_fun_zjversion/generated/i18n.dart';

//进度条
class ViewStateBusyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: CircularProgressIndicator(),
    );
  }
}

class ViewStateWidget extends StatelessWidget {
  String message;
  Widget image;
  Widget buttonText;
  VoidCallback onPressed;

  ViewStateWidget({Key key,this.message, this.image, this.buttonText, @required this.onPressed}):super(key:key);

  @override
  Widget build(BuildContext context) {
    return new Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          image??Icon(IconFonts.pageError,size: 80,color: Colors.grey[500],),
          Padding(
            padding: const EdgeInsets.fromLTRB(30, 20, 30, 150),
            child: Text(message??S.of(context).viewStateButtonError,style: Theme.of(context).textTheme.body1.copyWith(color: Colors.grey),),
          ),
          ViewStateButton(onPressed: onPressed,child: buttonText,)
        ],
      ),
    );
  }
}

/// 页面无数据
class ViewStateEmptyWidget extends StatelessWidget {
  final String message;
  final Widget image;
  final Widget buttonText;
  final VoidCallback onPressed;

  const ViewStateEmptyWidget(
      {Key key,
        this.image,
        this.message,
        this.buttonText,
        @required this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ViewStateWidget(
      onPressed: this.onPressed,
      image: image ??
          const Icon(
            IconFonts.pageEmpty,
            size: 100,
            color: Colors.grey,
          ),
      message: message ?? S.of(context).viewStateMessageEmpty,
      buttonText: buttonText ??
          Text(
            S.of(context).viewStateButtonRefresh,
            style: TextStyle(letterSpacing: 5),
          ),
    );
  }
}
/// 页面未授权
class ViewStateUnAuthWidget extends StatelessWidget {
  final String message;
  final Widget image;
  final Widget buttonText;
  final VoidCallback onPressed;

  const ViewStateUnAuthWidget(
      {Key key,
        this.image,
        this.message,
        this.buttonText,
        @required this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ViewStateWidget(
      onPressed: this.onPressed,
      image: image ?? ViewStateUnAuthImage(),
      message: message ?? S.of(context).viewStateMessageUnAuth,
      buttonText: buttonText ??
          Text(
            S.of(context).viewStateButtonLogin,
            style: TextStyle(wordSpacing: 5),
          ),
    );
  }
}

class ViewStateUnAuthImage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Hero(
        tag: 'loginLogo', 
        child: Image.asset(
          ImageHelper.wrapAssets('login_logo.png'),
          width: 130,
          height: 100,
          fit: BoxFit.fitWidth,
          color: Theme.of(context).accentColor,
          colorBlendMode: BlendMode.srcIn,
        )
    );
  }
}



class ViewStateButton extends StatelessWidget {
  final VoidCallback onPressed;
  final Widget child;

  ViewStateButton({@required this.onPressed, this.child});

  @override
  Widget build(BuildContext context) {
    return new OutlineButton(
      onPressed: onPressed,
      child: child??Text(S.of(context).viewStateButtonRetry,style: TextStyle(wordSpacing: 5),),
      textColor: Colors.grey,
      splashColor: Theme.of(context).splashColor,
      highlightColor: Theme.of(context).splashColor,
    );
  }
}

